﻿@using System.ComponentModel

<p>Column alignment: @columnAlign</p>
<EnumRadioGroup TEnum="ColumnAlign" @bind-Value="@columnAlign" />

<Table TItem="Data" DataSource="@data">
    @*By default, ColumnAlign is Left (if Align property isn't defined)*@
    <PropertyColumn Property="c=>c.Name" Align="@columnAlign" />
    <PropertyColumn Property="c=>c.Age" Align="@columnAlign" Sortable />
    <PropertyColumn Property="c=>c.Address" Align="@columnAlign">
        <TitleTemplate>
            <span><Icon Type="@IconType.Outline.Environment" /> Address</span>
        </TitleTemplate>
    </PropertyColumn>
  <PropertyColumn Property="c=>c.Tags" Align="columnAlign">
        @foreach (var tag in context.Tags)
        {
            var color = tag.Length > 5 ? TagColor.GeekBlue : TagColor.Green;
            <Tag Color="@color">@tag</Tag>
        }
    </PropertyColumn>
    <ActionColumn Title="Action" Align="columnAlign">
        <Space Size="SpaceSize.Middle">
            <SpaceItem>
                <a>Invite @context.Name</a>
            </SpaceItem>
            <SpaceItem>
                <a>Delete</a>
            </SpaceItem>
        </Space>
    </ActionColumn>
</Table>


@code{
    ColumnAlign columnAlign = ColumnAlign.Left;

    readonly Data[] data = new Data[]
    {
        new()
        {
            Key = "1",
            Name = "John Brown",
            Age = 32,
            Address = "New York No. 1 Lake Park",
            Tags = new[] {"nice", "developer"}
        },
        new()
        {
            Key = "2",
            Name = "Jim Green",
            Age = 42,
            Address = "London No. 1 Lake Park",
            Tags = new[] { "loser"}
        },
        new()
        {
            Key = "3",
            Name = "Joe Black",
            Age = 32,
            Address = "Sidney No. 1 Lake Park",
            Tags = new[] { "cool", "teacher" }
        }
        };

    public class Data
    {
        [DisplayName("Key")]
        public string Key { get; set; }

        [DisplayName("Name")]
        public string Name { get; set; }

        [DisplayName("Age")]
        public int Age { get; set; }

        [DisplayName("Address")]
        public string Address { get; set; }

        [DisplayName("Tags")]
        public string[] Tags { get; set; }
    }

}